/**
 * 页码的组件
 * Created by wubin on 2016-12-18.
 */
import {Component, Input, Output, EventEmitter, OnChanges, Renderer, ViewChild, ElementRef} from "@angular/core";
@Component({
    selector: "pagination-c",
    templateUrl: "./pagination-component.html",
    styleUrls: ["./style-source/pagination-component.scss"]
})
export class PaginationComponent implements OnChanges {
    @ViewChild("numberContainer") numberContainer: ElementRef;
    //该变量用于记录待显示的对象的总数
    @Input() totalCount: number = 0;
    //该变量用于记录每页待显示的总数
    @Input() perPage: number = 0;
    //该变量用于输出当前的页数
    @Output() currPage: EventEmitter<number> = new EventEmitter<number>();

    //该变量用于记录当前页数
    currPageNum: number = 0;
    //该变量用于记录总页数
    totalPage: number = 0;

    constructor(renderer: Renderer) {
    }

    ngOnChanges() {
        this.initTotalPage();
    }

    //该方法用于初始化总页数
    initTotalPage() {
        let pageResult = this.perPage ? this.totalCount / this.perPage : 0;
        if (pageResult > 0) {
            this.totalPage = Math.ceil(pageResult);
            this.currPageNum = 1;
            this.changePagination();
        }
    }

    //这个方法用于改变
    changePagination() {

    }
}
